package com.yunji.framework_template.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunji.framework_template.biz.service.UserLikesService;
import com.yunji.framework_template.common.web.Page;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.orm.persistence.model.UserLikes;

/**
 * Created by fenglibin on 2018/11/26.
 */
@Controller
@RequestMapping("/userLikes/")
public class UserLikesController {

    @Autowired
    UserLikesService userLikesService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<UserLikes>> selectAll() {
        return Result.success(userLikesService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<UserLikes> selectByPrimaryKey(Integer id) {
        return Result.success(userLikesService.selectByPrimaryKey(id));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<UserLikes>> selectByCondition(UserLikes record) {
        return Result.success(userLikesService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(UserLikes record) {
        return Result.success(userLikesService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(UserLikes record) {
        return Result.success(userLikesService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(UserLikes record) {
        return Result.success(userLikesService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<UserLikes>>> selectByPage(Page<UserLikes> page) {
        List<UserLikes> list = null;
        page = page.sequentialDisplayCalculate(userLikesService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = userLikesService.selectByPage(page);
        }
        Page<List<UserLikes>> result = new Page<List<UserLikes>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition1")
    @ResponseBody
    public Result<Integer> deleteByCondition(UserLikes record) {
        return Result.success(userLikesService.deleteByCondition(record));
    }

    @RequestMapping("delete1")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(Integer id) {
        return Result.success(userLikesService.deleteByPrimaryKey(id));
    }

}
